﻿@model CMS.Common.Helpers.PagedData<CMSApplication.Areas.Administration.Models.WorkModel>
<script>
    jQuery(document).ready(function ($) {
        $(".page-number").on("click", function () {
            var page = parseInt($(this).html());
            ExecForSearch({ page: page, type: 1 });
        });
        $("a.delete").click(function () {
            var $this = $(this);
            var item_id = $this.closest("tr").find(".Spanid").html();
            if (confirm("Bạn chắc chắn muốn xóa công việc: Mã = " + item_id + "?")) {
                $.get("/Work/Delete?Id=" + item_id, function () {
                    var page = parseInt($(".page-number-Current").html());
                    ExecForSearch({ type: 1 });
                });
            }
        });
    });
</script>
@if (Model.Data.Count() > 0)
{
    <table class="table dataTable" style="width:100%">
        <thead>
            <th style="text-align:center;">Mã</th>
            <th>Khách hàng</th>
            <th>Nhân viên</th>
            <th style="text-align:center;">Ngày thực hiện</th>
            <th>Trạng thái</th>
            <th style="text-align:right;">Chi phí</th>
            <th style="text-align:right;">Thu được</th>
            <th style="text-align:center; width:50px;">Tác vụ</th>
        </thead>
        <tbody>
            @foreach (var item in Model.Data)
            {
                <tr>
                    <td style="text-align:center;">
                        <span class="Spanid">@item.Id</span>
                    </td>
                    <td>
                        <span>@item.CustomerName</span>
                    </td>
                    <td>
                        <span>@item.StaffName</span>
                    </td>
                    <td style="text-align:center;">
                        <span>@string.Format("{0:dd/MM/yyyy}", item.AssignOn)</span>
                    </td>
                    <td>
                        <span>@item.StatusName</span>
                    </td>
                    <td style="text-align:right;">
                        <span>@{
                            if (item.Cost > 0)
                            { <text>@string.Format("{0:#,###}", item.Cost)</text> }
                            else
                            { <text>0</text> }
                        }</span>
                    </td>
                    <td style="text-align:right;">
                        <span>@{
                            if (item.Collected.HasValue && item.Collected.Value > 0)
                            { <text>@string.Format("{0:#,###}", item.Collected.Value)</text> }
                            else
                            { <text>0</text> }
                        }</span>
                    </td>
                    <td style="text-align:center;">
                        <a title="Chỉnh sửa » @item.Id" href="@Url.Action("Edit", "Work", new { id = item.Id})" class="icon-pencil"></a>
                        <a title="Xóa bỏ » @item.Id" href="javascript:void(0)" class="icon-trash delete"></a>
                    </td>
                </tr>
            }
        </tbody>
    </table>
    <div class="dataTables_paginate paging_full_numbers" id="tSortable_2_paginate">
        <span>
        @for (int m = 1; m <= Model.NumberOfPages; m++)
        {
            if (m == Model.CurrentPage)
            {
                <a href="javascript:void(0);" tabindex="0" class="paginate_active page-number-Current">@m</a>
            }
            else
            {
                <a class="paginate_button page-number" href="javascript:void(0);" tabindex="0">@m</a>
            }
        }
        </span>
    </div>
}
else
{
    <h2>Không có dữ liệu.</h2>
}
